﻿namespace TamTam.SharePoint2010.SocialGatherer {
    #region [ Usings ]

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.ServiceModel.Syndication;
    using Microsoft.SharePoint;
    using Microsoft.Office.Server.ActivityFeed;
    using Microsoft.Office.Server.UserProfiles;
    using TamTam.SharePoint2010.Social;
    using Microsoft.SharePoint.Administration;

    #endregion

    public class Program {

        /// <summary>
        /// main entry point for command line tool
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args) {
            
            if (args.Length == 1) {
                string siteUrl = args[0];
                using (SPSite site = new SPSite(siteUrl)) {
                    Console.WriteLine("Import started for Portal {0}",siteUrl);
                    SPServiceContext ctx = SPServiceContext.GetContext(site);
                    UserProfileManager upm = new UserProfileManager(ctx);

                    foreach (UserProfile profile in upm) {
                        string account = profile["AccountName"].Value as string;
                        if (TwitterActivityFeed.ProfileHasTwitter(profile)) {
                            int updates = TwitterActivityFeed.Import(site, profile);
                            Console.WriteLine("Imported {1} twitter updates for {0}.", account, updates);
                        }
                        if (BlogActivityFeed.ProfileHasBlog(profile)) {
                            int updates = BlogActivityFeed.Import(site, profile);
                            Console.WriteLine("Imported {1} blog updates for {0}.", account, updates);
                        }
                    }
                }
            }
        }
    }
}